<?php
declare (strict_types=1);

namespace app\api\controller\v4;

use app\common\models\Paper;

class Beta extends BaseController
{
    /**
     * 在线测评
     *
     * @return \think\Response
     */
    public function index()
    {
        return sucessMsg(200, '获取成功', [
            'paper' => $this->paper(),   //获取paper信息
            'paper2' => $this->paper2(),   //获取课程分类信息
        ]);
    }


    /**
     * 选择年级
     *
     * @return \think\Response
     */
    public function paper()
    {
        $where = input('title');//试卷名称
        $data = Paper::field('id,title,pid')
            ->where(['status' => 1, 'pid' => 0])
            ->where(function ($query) use ($where) {
                if ($where) {
                    $query->where('title', 'like', '%' . $where . '%');
                }
            })
            ->order(['id' => 'asc'])
            ->select();
        return $data;
    }

    /**
     * 课程
     *
     * @return \think\Response
     */
    public function paper2()
    {
        $where = input('title');//试卷名称
        $id = input('id/s');
        $data = Paper::where(['status' => 1, 'pid' => $id])
            ->field('id,title,pid')
            ->where(function ($query) use ($where) {
                if ($where) {
                    $query->where('title', 'like', '%' . $where . '%');
                }
            })
            ->order(['id' => 'asc'])
            ->select();
        return $data;
    }
}

